package com.example.myapplication;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;

@SuppressWarnings("ALL")
public class MainAdapter extends RecyclerView.Adapter<MainAdapter.ViewHolder> {

    private final ArrayList<SevendaysBase> arrayList;

    private OnItemClickListener onItemClickListener = null;

    public MainAdapter(ArrayList<SevendaysBase> arrayList) {

        this.arrayList = arrayList;

    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

        SevendaysBase bean = arrayList.get(position);
//        holder.addressTextview.setText(bean.getData);
//        holder.queryTextview.setOnClickListener(v -> {
//            if (onItemClickListener!=null)onItemClickListener.onClick(position,bean);
//        });
//        holder.ipTextview.setOnClickListener(v -> {
//            if (onItemClickListener!=null)onItemClickListener.onClick1(position,bean);
//
//        });
//        holder.addressTextview.setOnClickListener(v -> {
//            if (onItemClickListener!=null)onItemClickListener.onClick1(position,bean);
//        });
//        holder.ipRelativeLayout.setOnClickListener(v -> {
//            if (onItemClickListener!=null)onItemClickListener.onClick1(position,bean);
//        });

    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup group, int viewType) {
        View view = LayoutInflater.from(group.getContext()).inflate(R.layout.item_main, group, false);
        return new ViewHolder(view);

    }

    @Override
    public int getItemCount() {

        return arrayList.size();

    }

    @SuppressWarnings("unused")
    public void setOnItemClickListener(OnItemClickListener listener) {

        this.onItemClickListener = listener;

    }

    @SuppressWarnings("unused")
    public interface OnItemClickListener {

        void onClick(int i, IpBean ipBean);
        void onClick1(int i, IpBean ipBean);

    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        private AppCompatTextView ipTextview;
        private AppCompatTextView queryTextview;
        private AppCompatTextView addressTextview;
        private RelativeLayout ipRelativeLayout;

        private ViewHolder(View view) {
            super(view);
            ipTextview = view.findViewById(R.id.ipTextview);
            queryTextview = view.findViewById(R.id.queryTextview);
            addressTextview = view.findViewById(R.id.addressTextview);
            ipRelativeLayout = view.findViewById(R.id.ipRelativeLayout);
        }


    }

}
